Facing issue building a simple RAG application using RetrievalQA

Hi all, Here is a simple RAG app code, I am facing issue running it. Issue probably lies in the HuggingFaceEndpoint’s repo_id used. Could you please guide me what repo_id should be used here? Also, how to identify when to use which repo_id?

Here is the code:

from langchain_community.document_loaders import TextLoader

from langchain.text_splitter import RecursiveCharacterTextSplitter

from langchain_huggingface import HuggingFaceEmbeddings, HuggingFaceEndpoint

from langchain_community.vectorstores import FAISS

from langchain.chains import RetrievalQA

from dotenv import load_dotenv

load_dotenv()

# Loading a text file

loader = TextLoader("./Dummy_docs/Test_doc_1.txt")

documents = loader.load()

# Splitting the text into manageable chunks

splitter = RecursiveCharacterTextSplitter(chunk_size=500, chunk_overlap=50)

chunks = splitter.split_documents(documents)

# Converting document chunks into embeddings and store in FAISS

embedding_model = HuggingFaceEmbeddings()

vectorstore = FAISS.from_documents(chunks, embedding_model)

# Creating a retriever from the vectorstore

retriever = vectorstore.as_retriever()

# Initializing the LLM endpoint

llm = HuggingFaceEndpoint(

repo_id="tiiuae/falcon-7b-instruct",

provider="auto"

)

# Create the RetrievalQA chain

qa_chain = RetrievalQA.from_chain_type(llm=llm, retriever=retriever)

# Define your user query

query = "Can I cancel my e-ticket booked online from Busways, at the counter?"

print(f"\nQuery: {query}\n")

# Get the answer

answer = qa_chain.run(query)

print("Answer:")

print(answer)

I am a beginner in GenAI. Than you for your support.

1 Like

The format of repo_id is correct, but since the model has not been deployed, it cannot be used as an API. Refer to the following post to find a model that can be used. Using a local model is more reliable, but requires a GPU.

3 Likes

Got yu! I went ahead to check the supporting inference points, and it worked using this:

Initializing the LLM endpoint

llm = HuggingFaceEndpoint(
repo_id=“HuggingFaceH4/zephyr-7b-beta”
)

Thanks again!

3 Likes